using System.Collections;
using System.Collections.Generic;
using FwkLight.Persistence;
using NHibernate;

namespace FwkLight.Domain.Fetching
{
  public class ListMultiCriteriaFetcher<EntityType> : MultiCriteriaFetcher<EntityType>, IListMultiCriteriaFetcher<EntityType> where EntityType : class
  {
    private readonly ISession _session;

    public ListMultiCriteriaFetcher(ISession session)
    {
      _session = session;
    }

    public IList<EntityType> LoadList()
    {
      return LoadList(_session);
    }

    public IList<EntityType> LoadList(ISession session)
    {
      IList<EntityType> ret = new List<EntityType>();

      IList list = LoadDefinedList(session);
      foreach (var entity in list)
      {
        var ent = entity as EntityType;
        if (ent != null)
          ret.Add(ent);
      }

      return ret;
    }
  }
}